﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="OAclient.Common" %>

<script language="javascript" type="text/javascript" src="../../Scripts/datepicker/WdatePicker.js"></script>

<script type="text/javascript">
    $(function() {
        $(".datepicker").datepicker();
        $("#SearchStaffOutAddrName").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "/Home/SearchStaffOutAddr",  //要查询的Action
                    type: "POST",  //Post提交
                    dataType: "json", //json格式数据，默认是text
                    data: { keyword: request.term }, //参数，不知道为什么？请指点
                    success: function(data) {
                        response($.map(data, function(item) {
                            return { label: item.text, value: item.value }; //将返回的jsonresult的属性赋值给autocomplete item
                        }))
                    }
                })
            },
            select: function(event, ui) {
                var t = ui.item.label; //'马军 事业部 员工'
                var arr = t.split(' ');
                $('#SearchStaffOutAddrName').val(arr[0]);  //选中item的文本
                $('#SearchLxrName').val(arr[1]);
                $('#SearchDhNum').val(arr[2]);
                $('#SearchStaffOutAddrId').val(ui.item.value); //选中item的值
                return false;
            },
            minLength: '0'
        })

        tableSelectOrder("#WcdjList .table_style");
//        $("#WcdjList #list_mytable").html(data);
    });
</script>

<script type="text/javascript">
    $(function() {
        $.ajax({
            type: "POST",
            url: "/Wcdj/ListTable",
            data: {},
            success: function(data) {
            $("#WcdjList #list_mytable").html(data);
            }
        });
    });
</script>

<script type="text/javascript">
    function enable() {
        document.getElementById('wcdj_date').disabled = true;
    }
</script>

<script type="text/javascript">
    var row_count = 0;
    function addNew() {
        var my_table = $("#my_table");
        var firstTr = my_table.find('tbody>tr:first');
        var row = $("<tr></tr>");
        var td = $("<td></td>");
        var td1 = $("<td></td>");
        var td2 = $("<td></td>");
        var td3 = $("<td></td>");
        var td4 = $("<td></td>");
        var td5 = $("<td></td>");
        var td6 = $("<td></td>");
        var td7 = $("<td></td>");
        var td8 = $("<td></td>");
        var td9 = $("<td></td>");
        var wcdj_date = $("#WcdjList #wcdj_date").val();
        var wcdj_stime = $("#WcdjList #wcdj_stime").val();
        var wcdj_pretime = $("#WcdjList #wcdj_pretime").val();
        var SearchStaffOutAddrName = $("#WcdjList #SearchStaffOutAddrName").val();
        var wcdj_reason = $("#WcdjList #wcdj_reason").val();
        var SearchLxrName = $("#WcdjList #SearchLxrName").val();
        var SearchDhNum = $("#WcdjList #SearchDhNum").val();
        var wcdj_mark = $("#WcdjList #wcdj_mark").val();
        td.append($("<label>" + wcdj_date + "</label>"));
        td1.append($("<label>" + SearchStaffOutAddrName + "</label>"));
        td2.append($("<label>" + wcdj_reason + "</label>"));
        td3.append($("<label>" + SearchLxrName + "</label>"));
        td4.append($("<label>" + SearchDhNum + "</label>"));
        td5.append($("<label>" + wcdj_stime + "</label>"));
        td6.append($("<label>" + wcdj_pretime + "</label>"));
        td7.append($("<label></label>"));
        td8.append($("<label>" + wcdj_mark + "</label>"));
        td9.append($("<label></label>"));
        row.append(td);
        row.append(td1);
        row.append(td2);
        row.append(td3);
        row.append(td4);
        row.append(td5);
        row.append(td6);
        row.append(td7);
        row.append(td8);
        row.append(td9);
        my_table.prepend(row);
        row_count++;
    } 
</script>


<script type="text/javascript">

    function submitAdd() {
        var wcdj_date = $("#WcdjList #wcdj_date").val();
        var wcdj_stime = $("#WcdjList #wcdj_stime").val();
        var wcdj_pretime = $("#WcdjList #wcdj_pretime").val();
        var SearchStaffOutAddrName = $("#WcdjList #SearchStaffOutAddrName").val();
        var wcdj_reason = $("#WcdjList #wcdj_reason").val();
        var SearchLxrName = $("#WcdjList #SearchLxrName").val();
        var SearchDhNum = $("#WcdjList #SearchDhNum").val();
        var wcdj_mark = $("#WcdjList #wcdj_mark").val();
        $.ajax({
            type: "POST",
            url: "/Wcdj/WcdjList",
            data: { "wcdj_date": wcdj_date, "wcdj_stime": wcdj_stime, "wcdj_pretime": wcdj_pretime, "SearchStaffOutAddrName": SearchStaffOutAddrName,
                "wcdj_reason": wcdj_reason, "SearchLxrName": SearchLxrName, "SearchDhNum": SearchDhNum, "wcdj_mark": wcdj_mark
            },
            success: function(restag) {
                $("#WcdjList #wcdj_stime").val("");
                $("#WcdjList #wcdj_pretime").val("");
                $("#WcdjList #SearchStaffOutAddrName").val("");
                $("#WcdjList #wcdj_reason").val("");
                $("#WcdjList #SearchLxrName").val("");
                $("#WcdjList #SearchDhNum").val("");
                $("#WcdjList #wcdj_mark").val("");
            }
        });
    }

    function sureComeback(id, name) {
        var wcdj_id = name;
        var lab_id = "lab" + name;
        var wcdj_comeback = $("#WcdjList #wcdj_comeback").val();
        //        var wcdj_id = $("#WcdjList #wcdj_id").val();
        var date = new Date();
        var nowdate = date.getHours() + ":" + date.getMinutes();
        //alert(nowdate);
        $.ajax({
            type: "POST",
            url: "/Wcdj/ListTable",
            data: {
                "wcdj_id": wcdj_id, "wcdj_comeback": wcdj_comeback
            },
            success: function(restag) {
                document.getElementById(id).style.display = 'none';
                document.getElementById(lab_id).innerHTML = nowdate;
            }
        });
    }

    function delCode(id) {
        var wcdj_idDel = id;
        $.ajax({
            type: "POST",
            url: "/Wcdj/ListTable",
            data: { "wcdj_idDel": wcdj_idDel
            },
            success: function(restag) {
            $(function() {
                $.ajax({
                    type: "POST",
                    url: "/Wcdj/ListTable",
                    data: {},
                    success: function(data) {
                        $("#WcdjList #list_mytable").html(data);
                    }
                });
            });
            }
        });
    }
    
    
</script>

<script type="text/javascript">
    function givevalue() {
        document.getElementById('wcdj_id').value = document.getElementById('h').value;
    }
</script>

<script type="text/javascript">
    function submitwcdj_return() {
        document.getElementById("wcdj_return").value = "1";
    }
</script>

<div id="WcdjList" style="padding-top: 35px;">
    <div style="font-family: 宋体,Arial, Helvetica, sans-serif; padding: 10px; margin-bottom: 10px;
        border: 2px solid #C1DAD7; border-top: 0PX;">
        <table bgcolor="#F6F9FC" cellpadding="0px" cellspacing="0px" style="border-bottom: 0px;">
            <form action="/Wcdj/WcdjList" method="post">
            <tr style="height: 25px; background-color: #F6F9FC;">
                <td style="width: 90px;" align="right">
                    日期：
                </td>
                <td width="160px">
                    <input type="text" id="wcdj_date" name="wcdj_date" value="<%=ViewData["date"] %>"
                        onfocus="enable" readonly="readonly" />
                </td>
                <td width="220px" align="right">
                    出门时间:<input id="wcdj_stime" name="wcdj_stime" class="Wdate" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:'%y-%M-%d 00:00:00',maxDate:'%y-%M-{%d+1} 21:00:00'})" />
                </td>
                <td>
                    预计返回时间:<input id="wcdj_pretime" name="wcdj_pretime" class="Wdate" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:'#F{$dp.$D(\'wcdj_stime\')}'})" /><!--maxDate:'%y-%M-{%d+1} 00:00:00'-->
                </td>
            </tr>
            <tr style="height: 25px; background-color: #F6F9FC;">
                <td align="right">
                    外出地点:
                </td>
                <td colspan="3">
                    <input type="text" id="SearchStaffOutAddrName" name="SearchStaffOutAddrName" style="width: 614px;" />
                    <input type="hidden" id="SearchStaffOutAddrId" name="SearchStaffOutAddrId" style="width: 614px;" />
                </td>
            </tr>
            <tr style="height: 25px; background-color: #F6F9FC;">
                <td align="right">
                    外出事由:
                </td>
                <td colspan="3">
                    <input type="text" id="wcdj_reason" name="wcdj_reason" style="width: 614px;" />
                </td>
            </tr>
            <tr style="height: 25px; background-color: #F6F9FC;">
                <td style="font-family: 宋体,Arial, Helvetica, sans-serif;">
                    联系人:
                </td>
                <td colspan="3">
                    <input type="text" id="SearchLxrName" name="SearchLxrName" style="width: 614px;" />
                </td>
            </tr>
            <tr style="height: 25px; background-color: #F6F9FC;">
                <td>
                    电话:
                </td>
                <td colspan="3">
                    <input type="text" id="SearchDhNum" name="SearchDhNum" style="width: 614px;" />
                </td>
            </tr>
            <tr style="background-color: #F6F9FC;">
                <td style="vertical-align: top; border: 0px;" align="right">
                    备注:
                </td>
                <td colspan="3">
                    <textarea style="border: 1px solid #6C92AD; width: 614px;" id="wcdj_mark" rows="5"
                        name="wcdj_mark"></textarea>
                </td>
            </tr>
            <tr style="height: 40px; background-color: #F6F9FC; border-bottom: 0px;">
                <td colspan="4" style="padding-top: 10px; border-bottom: 0px;">
                    <input type="hidden" id="wcdj_return" name="wcdj_return" value="" />
                    <input type="button" value="提 交" onclick="submitAdd();addNew();" />
                </td>
            </tr>
            </form>
        </table>
    </div>
   <%-- <div style="border: 1px solid #C1DAD7; margin-bottom: 20px;">
        <table id="my_table" class="table_style" width="100%" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th>
                        时间
                    </th>
                    <th>
                        外出地点
                    </th>
                    <th>
                        外出事由
                    </th>
                    <th>
                        联系人
                    </th>
                    <th>
                        电话
                    </th>
                    <th>
                        出门时间
                    </th>
                    <th>
                        预计返回时间
                    </th>
                    <th>
                        实际返回时间
                    </th>
                    <th>
                        备注
                    </th>
                    <th>
                        删除当日记录
                    </th>
                </tr>
            </thead>
            <tbody>
                <%
                    System.Data.DataTable allInfo = ViewData["allInfo"] as System.Data.DataTable;
                    if (allInfo == null || allInfo.Rows.Count == 0)
                    {%>
                <tr>
                    <td colspan="0" style="text-align: center;">
                        当前无数据！
                    </td>
                </tr>
                <% }
                    else
                    {
                        for (int i = 0; i < allInfo.Rows.Count; i++)
                        {
                %>
                <tr>
                    <td style="display: none;">
                        <%=allInfo.Rows[i]["登记号"]%>
                    </td>
                    <td>
                        <%=allInfo.Rows[i]["登记日期"]%>
                    </td>
                    <td>
                        <%=allInfo.Rows[i]["外出地点"]%>
                    </td>
                    <td>
                        <%=allInfo.Rows[i]["外出事由"]%>
                    </td>
                    <td>
                        <%=allInfo.Rows[i]["联系人"]%>
                    </td>
                    <td>
                        <%=allInfo.Rows[i]["电话"] %>
                    </td>
                    <td>
                        <%=allInfo.Rows[i]["出门时间"]%>
                    </td>
                    <td>
                        <%=allInfo.Rows[i]["预计返回时间"]%>
                    </td>
                    <td style="padding: 0px; text-align: center;">
                        <%if (allInfo.Rows[i]["实际返回时间"].ToString() == "")
                          {%>
                        <input id="wcdj_comeback" name="wcdj_comeback" type="hidden" value="<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm") %>" />
                        <input id="sure<%=allInfo.Rows[i]["登记号"]%>" name="<%=allInfo.Rows[i]["登记号"] %>"
                            type="button" value="确认返回" onclick="sureComeback(this.getAttribute('id'),this.getAttribute('name'));" />
                        <label id="lab<%=allInfo.Rows[i]["登记号"]%>">
                        </label>
                        <%  } %>
                        <%else
                            {%>
                        <%=allInfo.Rows[i]["实际返回时间"]%>
                        <%} %>
                    </td>
                    <td title='<%=allInfo.Rows[i]["备注"].ToString() %>'>
                        <%=allInfo.Rows[i]["备注"].ToString().Length > 25 ? allInfo.Rows[i]["备注"].ToString().Remove(25) : allInfo.Rows[i]["备注"].ToString()%>
                    </td>
                    <td>
                        <%string a = ViewData["date"] as string; %>
                        <%string b = allInfo.Rows[i]["登记日期"].ToString(); %>
                        <%if (allInfo.Rows[i]["登记日期"].ToString() == a)
                          {%>
                        <input id="del<%=allInfo.Rows[i]["登记号"] %>" name="<%=allInfo.Rows[i]["登记号"] %>" type="button"
                            value="删 除" onclick="delCode(this.getAttribute('name'));" />
                        <% } %>
                    </td>
                </tr>
                <%
                    }
                    } %>
            </tbody>
        </table>
    </div>
    <div id="pageLink" style="padding-left: 15px; padding-right: 15px;">
        <%var pageInfo = ViewData["pageInfo"] as PagingInfo; %>
        <%if (pageInfo != null)
          {  %>
        <%=Ajax.PageLinks(pageInfo, index => Url.Action("WcdjList",new
                {
                    page = index,
                    //wfname = ViewData["searchtaskname_wfstart"],
                    //clrname = ViewData["searchclrname_wfstart"],
                    //stime = ViewData["searchstime_wfstart"],
                    //etime = ViewData["searchetime_wfstart"],
                }), new AjaxOptions { UpdateTargetId = "workarea-wcdj-1" })%>
        <%} %>
    </div>--%>
    <div id="list_mytable"></div>
</div>
